﻿@using ControleRepresentante.Logic.Models
@using ControleRepresentante.Logic.Repositories
@using WebSite.ViewModels
@using WebSite.Controllers
@using System.Linq

@model CompareViewModel
@using (Html.BeginForm())
{
    @Model.GetSearchForm(Html, 1)
    <input type="submit" value="Comparar" />
}
<hr />
@{
    int yearsPerTable = new[] {CompareTotal.TotalLiquido, CompareTotal.TotalMercadoria}.Contains(Model.CompareTotal) ? 7 : Model.CompareYears.Count();
    int tableCount = (int) Math.Ceiling((decimal)Model.CompareYears.Count() / (decimal)yearsPerTable);
}
@for (int i = 0; i < tableCount; i++)
{
    <table style="border-color: Black; border-width: 1px; border-style: solid; border-spacing: 0px; border-collapse: collapse; color: black" border="1" cellspacing="0" cellpadding="3" align="center">
        <tr style="background-color: #8DB4E2">
            <td style="text-align: center">Mes\Ano</td>
            @{IEnumerable<CompareYear> compareYears = Model.CompareYears.Skip(i * yearsPerTable).Take(yearsPerTable);}
            @foreach (CompareYear compareYear in compareYears)
            {
                <td style="text-align: center">@compareYear.Year</td>
            }
        </tr>
        @for (int month = 1; month <= 12; month++)
        {
            <tr>
            <td style="background-color: #C5D9F1; text-align: center">@month</td>
            @foreach (CompareYear compareYear in compareYears)
            {
                double? total = compareYear[month];
                <td style="background-color:#@Model.GetColor(total); text-align: right">@String.Format("{0:###,###.##}", total)</td>
            }
</tr>
        }
    </table>
    <br />
}
<hr/>
<div align="center">
@foreach (CompareYear compareYear in Model.CompareYears.Reverse())
{
    Dictionary<string, double> values = new Dictionary<string, double>();
    for (int i = 1; i <= 12; i++)
    {
        values[i.ToString()] = compareYear[i] ?? 0;
    }
    string title = compareYear.Year.ToString();
    @Html.GoogleBarChart(title, new ChartSeries(title, values), 250, 150);
}
</div>